// license-header java merge-point
/**
 * This is only generated once! It will never be overwritten.
 * You can (and have to!) safely modify it by hand.
 */
package edu.uwlax.cs.oayonlinestore.entities;

import java.util.Date;

import edu.uwlax.cs.oayonlinestore.stadis.RetExStatus;
import edu.uwlax.cs.oayonlinestore.vo.RetExFormVO;

/**
 * @see edu.uwlax.cs.oayonlinestore.entities.RetExForm
 */
public class RetExFormDaoImpl extends RetExFormDaoBase {
	/**
	 * Retrieves the entity object that is associated with the specified value
	 * object from the object store. If no such entity object exists in the
	 * object store, a new, blank entity is created
	 */
	private RetExForm loadRetExFormFromRetExFormVO(RetExFormVO retExFormVO) {
		RetExForm retExForm = this.load(retExFormVO.getId());
		if (retExForm == null) {
			retExForm = RetExForm.Factory.newInstance();
		}
		return retExForm;
	}

	public RetExForm retExFormVOToEntity(RetExFormVO retExFormVO) {
		RetExForm entity = this.loadRetExFormFromRetExFormVO(retExFormVO);
		this.retExFormVOToEntity(retExFormVO, entity, true);
		entity.setStatus(RetExStatus.fromString(retExFormVO.getStatus()));
		return entity;
	}

	public void toRetExFormVO(RetExForm source, RetExFormVO target) {
		super.toRetExFormVO(source, target);
		target.setStatus(source.getStatus().getValue());
		target.setUser(getUserDao().toUserVO(
				source.getOrderItem().getOrder().getUser()));
		target.setOrderItem(getOrderItemDao().toOrderItemVO(
				source.getOrderItem()));
		if (source.getDate() != null)
			target.setDate(new Date(source.getDate().getTime()));
	}

}